package org.example.test.domain.strategy;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.example.domain.strategy.service.armory.IStrategyArmory;
import org.example.domain.strategy.service.armory.IStrategyDispatch;
import org.example.infrastructure.dao.IAwardDao;
import org.example.infrastructure.dao.po.Award;
import org.example.infrastructure.redis.IRedisService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.api.RMap;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName StrategyArmoryDispatchTest
 * @Description TODO
 * @Author dfx
 * @Date 2024/10/11 20:22
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class StrategyArmoryDispatchTest {

    @Resource
    private IStrategyArmory strategyArmory;


    @Resource
    private IStrategyDispatch strategyDispatch;

    @Before
    public  void  test_strategyArmory(){
         boolean success = strategyArmory.assembleLotteryStrategy(100001L);

          log.info("测试结果：{}", JSON.toJSONString(success));
    }

    @Test
    public  void  test_getAssembleRandomVal(){
        log.info("测试结果：{}-奖品ID值", strategyDispatch.getRandomAwardId(100001L));
    }



    /**
     * 从装配的策略中随机获取奖品ID值
     */
    @Test
    public void test_getRandomAwardId() {
        log.info("测试结果：{} - 奖品ID值", strategyDispatch.getRandomAwardId(100001L));
    }


    /**
     * 根据策略ID+权重值，从装配的策略中随机获取奖品ID值
     */
    @Test
    public void test_getRandomAwardId_ruleWeightValue() {
        log.info("测试结果：{} - 60 策略配置", strategyDispatch.getRandomAwardId(100001L,"60:102,103,104,105"));
        log.info("测试结果：{} - 200 策略配置", strategyDispatch.getRandomAwardId(100001L,"200:106,107"));
        log.info("测试结果：{} - 1000 策略配置", strategyDispatch.getRandomAwardId(100001L,"1000:105"));
    }


    @Resource
    private IRedisService redisService;

    @Test
    public void test_map() {
        RMap<Integer, Integer> map = redisService.getMap("strategy_id_100001");
        map.put(1, 101);
        map.put(2, 101);
        map.put(3, 101);
        map.put(4, 102);
        map.put(5, 102);
        map.put(6, 102);
        map.put(7, 103);
        map.put(8, 103);
        map.put(9, 104);
        map.put(10, 105);

        log.info("测试结果：{}", redisService.getMap("strategy_id_100001").get(1));
    }

}